home *** CD-ROM | disk | FTP | other *** search
/ Macmillan Math: Grade 1 …Pupil's Edition (Florida) / Math Grade 1 - Pupil's Edition (Florida).iso / pc / corsair / generic / javascript / slideshow.js < prev    next >
Encoding:
Text File  |  2003-10-21  |  4.4 KB  |  208 lines

  1. var activeslide = 1;  // stores the number of the activeslide
  2. var layers = 0;  // stores the total number of slides
  3. var obj=0;
  4. var ns4, ie4;
  5.  
  6. function init() //initialize all divs. Called onload of body.
  7. {
  8.  
  9.  
  10.     ns4 = (document.layers)? true:false;
  11.     ie4 = (document.all)? true:false;
  12.  
  13.  
  14. // hide the divload layer
  15. // hide all layers except the first layer
  16.     if (ns4)
  17.     {  
  18.         layers = document.layers.length -4;
  19.  
  20.     }
  21.     else
  22.     {
  23.         var divname;
  24.         for (i=1;;i++)
  25.         {
  26.             divname="div"+i;
  27.             if (document.all(divname) == null)
  28.             {
  29.                 break;
  30.             }
  31.         }
  32.  
  33.         layers= i - 1;
  34.  
  35.     }
  36.  
  37.     layerHide('divload');
  38.     layerShow('div1');
  39.  
  40.     // create the navigation bar for the first time.
  41.     createNavBar();
  42. }
  43.  
  44.  
  45. function showNextSlide()  //called when the user clicks on the 'Next Slide' Arrow
  46. {
  47.     if (activeslide < layers )
  48.     {
  49.         showSlide((activeslide + 1));
  50.     }
  51.  
  52. }
  53.  
  54. function showPrevSlide() //called when the user clicks on the 'Previous Slide' Arrow
  55. {
  56.     if (activeslide > 1)
  57.     {
  58.         showSlide((activeslide - 1));
  59.     }
  60. }
  61.  
  62.  
  63. function layerHide(layername) // Browser independent implementation for hiding a layer
  64. {
  65.     if (ns4)
  66.     {
  67.         document.eval(layername).visibility = "hide";
  68.     }
  69.     else
  70.     {
  71.              
  72.         document.all(layername).style.visibility = "hidden";
  73.     }
  74.  
  75. }
  76.  
  77. function layerShow(layername) // Browser independent implementation for showing a layer
  78. {
  79.     if (ns4)
  80.     {
  81.         document.eval(layername).visibility = "show";
  82.     }
  83.     else
  84.     {
  85.         document.all(layername).style.visibility = "visible";
  86.     }
  87.  
  88. }
  89.  
  90. function showSlide(obj) // to show the slide selected from the navigation bar (either by clicking on the slide number)
  91. {
  92.     activeslide = obj;
  93.  
  94.     
  95.     if (activeslide == 1) // If the first slide is active, display the Dummy 'Prev Arrow' 
  96.     {
  97.         layerShow('divDummyPrev');
  98.         layerHide('divDummyNext');
  99.     }
  100.     else if (activeslide > 1 && activeslide < layers) // hide the Dummy 'Prev, Next Arrows'
  101.     {
  102.         layerHide('divDummyPrev');
  103.         layerHide('divDummyNext');
  104.  
  105.     }
  106.     else if (activeslide == layers) // If the first slide is active, display the Dummy 'Next Arrow' 
  107.     {
  108.         layerHide('divDummyPrev');
  109.         layerShow('divDummyNext');
  110.  
  111.     }
  112.  
  113.     var divname;
  114.  
  115.     // loop runs through all the divs and hides them except the one selected by the user
  116.  
  117.     for (i=1; i <= layers ;i++)
  118.     {
  119.         divname="div"+i;
  120.  
  121.         if (i != obj)
  122.         {
  123.             layerHide(divname);
  124.         }
  125.         else
  126.         {
  127.             layerShow(divname);
  128.         }
  129.     }
  130.  
  131.     createNavBar();     // create the navigation bar as per the current status
  132. }
  133.  
  134.  
  135. function createNavBar()   // to create the navigation bar based on the current status of slides.
  136. {
  137.  
  138.     // navbarHtml stores the HTML for the navigation. The contents of this variable ar written into the divNavBar
  139.  
  140.     navbarHtml = '<table border="0" cellpadding="0" cellspacing="0" height="36"><tr>';
  141.  
  142.     navbarHtml = navbarHtml + '<td width="230" align="center" class="slidetext">Slide no: ';
  143.  
  144.     var i; // Stores the value of the starting number of the slide to be shown in the nav bar
  145.  
  146.     if (activeslide > 3)  // to decide the starting slide number in the nav bar. Only 5 number should be displayed in the nav bar. If the active slide is greater than 3 than 2 number on either side of the active slide will be displayed.
  147.     {
  148.  
  149.         if (activeslide < (layers - 2))
  150.         {
  151.             i = (activeslide - 2);    
  152.         }
  153.         else if (layers > 5)
  154.         {
  155.             i = (layers - 4);
  156.         }
  157.         else
  158.         {
  159.             i= 1;
  160.         }
  161.  
  162.     }
  163.     else
  164.     {
  165.         i = 1;
  166.     }
  167.  
  168.  
  169.     for (a=1; (i < (layers +1)) && (a < 6); i++, a++)    // Loop runs from the starting number set above till 5 numbers after that or till end of slides. This loop construct the numbers to be displayed in the nav bar.
  170.     {
  171.         
  172.         if (i != activeslide)
  173.         {
  174.             navbarHtml = navbarHtml + '<span class="active"><a href="javascript:showSlide(' + i + ')">' + i + '</a> </span>';
  175.         }
  176.         else
  177.         {
  178.             navbarHtml = navbarHtml + '<span class="inactive">' + i + ' </span>';
  179.         }
  180.  
  181.         if ((i < layers) && (a < 5))
  182.         {
  183.             navbarHtml = navbarHtml + ' | ';
  184.         }
  185.     
  186.     }    // end of loop
  187.  
  188.     navbarHtml = navbarHtml + '</td>';
  189.  
  190.     navbarHtml = navbarHtml + '</tr></table>  ';  // the blank spaces are for IE 5 on Mac. Please do not remove them.
  191.  
  192.     // write the contents of navbarHtml into divNavBar.
  193.     if (ns4)
  194.     {
  195.         document.layers["divNavBar"].document.open();
  196.         document.layers["divNavBar"].document.write(navbarHtml);
  197.         document.layers["divNavBar"].document.close();
  198.  
  199.     }
  200.     else
  201.     {
  202.         document.all["divNavBar"].innerHTML = navbarHtml;
  203.  
  204.     }
  205.  
  206. }
  207.  
  208.